package com.chucang.shucang.usr.controller;

import com.chucang.shucang.common.base.utils.R;
import com.chucang.shucang.usr.exception.UsrErrorCode;
import com.chucang.shucang.usr.service.RealNameAuthService;
import com.chucang.shucang.usr.vo.RealNameAuthInfoResVO;
import com.chucang.shucang.usr.vo.RealNameAuthVO;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Objects;

/**
 * 用户实名认证信息
 *
 * @author flitsneak flitsneak@gmail.com
 * @since 1.0.0 2022-09-12
 */
@RestController
@RequestMapping("/realnameauth")
@RequiredArgsConstructor
@Api(tags = "用户实名认证信息")
public class RealNameAuthController {

    private final RealNameAuthService realNameAuthService;

    /**
     * 实名认证
     *
     * @param realNameAuthVO rna
     * @return r
     */
    @PostMapping("/doAuth")
    public R<RealNameAuthInfoResVO> doAuth(@Valid @RequestBody RealNameAuthVO realNameAuthVO) {
        RealNameAuthInfoResVO realNameAuthInfoResVO = realNameAuthService.doAuth(realNameAuthVO);
        if (Objects.isNull(realNameAuthInfoResVO)) {
            return R.failed(UsrErrorCode.USER_REAL_NAME_AUTH_FAIL.getCode(), UsrErrorCode.USER_REAL_NAME_AUTH_FAIL.getMsg());
        }

        return R.ok(realNameAuthInfoResVO);
    }
}